const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    url: app.apiroot,
    qrcode:"",
  },

  onShow: function(){
    app.loginState(()=>{
      this.setData({
        ucode: app.globalData.loginuser.ucode
      })
      this.getCode();
    },true);
  },

  //生成二维码
  getCode: function () {
    wx.showLoading({title: '生成邀请码',mask: true})
    var ucode = app.globalData.loginuser.ucode;
    app.api().Post('openapi/v1/user/miniprogramcode', {
      scene: {ucode:ucode},
      page: 'pages/index/index',
      name: 'smartbc_'+app.globalData.loginuser.ucode
    },(result)=>{
      this.setData({
        qrcode: result.data,
      })
      wx.hideLoading();
    })
  },

  //分享按钮
  onShareAppMessage: function (res) {
    var ucode = app.globalData.loginuser.ucode;
    return {
      desc: app.appname,
      path: '/tab/user?ucode='+ucode
    }
  },
})